package com.example.administrator.familfinalcialmanagement.ui.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.example.administrator.familfinalcialmanagement.R;
import com.example.administrator.familfinalcialmanagement.bean.ToastBean;

import java.util.List;

public class ToastAdapter extends ArrayAdapter {
    private List<ToastBean> list;
    private Context context;
    private static LayoutInflater inflater=null;
    public int tag=-1;
    public ToastAdapter(Context con, List<ToastBean> list){
        super(con,0);
        this.context=con;
        this.list=list;
        Log.e("TAG",list.size()+"");
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if(convertView == null ) {
            holder = new ViewHolder();
            inflater=LayoutInflater.from(context);
            convertView = inflater.inflate(R.layout.toast_item,null);
            holder.tv_title = (TextView)convertView.findViewById(R.id.tv_title);
            holder.tv_time = (TextView)convertView.findViewById(R.id.tv_time);
            holder.tv_text = (TextView)convertView.findViewById(R.id.tv_text);
            convertView.setTag(holder);

        }else {
            holder = (ViewHolder)convertView.getTag();

        }
        holder.tv_title.setText(list.get(position).getTitle());
        holder.tv_time.setText(list.get(position).getToastTime());
        holder.tv_text.setText(list.get(position).getInfo());

        return convertView;
    }
    static class ViewHolder {
        public TextView tv_title,tv_time,tv_text;

    }

}
